package com.hpf.redis7.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;

@Component
@Slf4j
public class CheckUtils {
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public boolean checkWithBloomFilter(String checkItem, String key) {
        int hashValue = Math.abs(key.hashCode());
        long index = (long) (hashValue % Math.pow(2, 32));
        boolean existOK = Boolean.TRUE.equals(redisTemplate.opsForValue().getBit(checkItem, index));
        log.info("--->key:" + key + " 对应坑位下标index: " + index + " 是否存在：" + existOK);

        return existOK;
    }
}
